package com.lq.dubbo.rocketmq.shop.service;

import com.alibaba.dubbo.config.annotation.Service;
import com.lq.dubbo.rocketmq.shop.api.ICouponService;
import com.lq.dubbo.rocketmq.shop.constant.ShopCode;
import com.lq.dubbo.rocketmq.shop.entity.Result;
import com.lq.dubbo.rocketmq.shop.exception.CastException;
import com.lq.dubbo.rocketmq.shop.mapper.TradeCouponMapper;
import com.lq.dubbo.rocketmq.shop.shop_pojo.TradeCoupon;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @program: dubborocketmqshop
 * @description:
 * @author: LQ
 * @create: 2021-06-08 15:24
 */
@Component
@Service
public class CouponServiceImpl implements ICouponService {

    @Autowired
    TradeCouponMapper couponMapper;

    @Override
    public TradeCoupon findOne(Long couponId) {
        if (couponId == null) {
            CastException.cast(ShopCode.SHOP_REQUEST_PARAMETER_VALID);
        }
        TradeCoupon coupon = couponMapper.selectByPrimaryKey(couponId);
        return coupon;
    }

    @Override
    public Result updateCouponStatus(TradeCoupon coupon) {
        if (coupon == null || coupon.getOrderId() == null) {
            CastException.cast(ShopCode.SHOP_REQUEST_PARAMETER_VALID);
        }
        // 更新优惠券状态
        int i = couponMapper.updateByPrimaryKey(coupon);
        return new Result(ShopCode.SHOP_SUCCESS.getSuccess(), ShopCode.SHOP_SUCCESS.getMessage());
    }
}
